package com.wm.web.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.SessionAware;

import com.wm.bean.UserComment;
import com.wm.comm.Constant;
import com.wm.service.UserCommentService;
import com.wm.service.web.PageList;
import com.wm.service.web.Pages;

public class AdminUserComment extends BaseAction{
	private static final Log logger = LogFactory.getLog(AdminUserComment.class);
	
	private UserCommentService userCommentService;

	public UserCommentService getUserCommentService() {
		return userCommentService;
	}

	public void setUserCommentService(UserCommentService userCommentService) {
		this.userCommentService = userCommentService;
	}

	
	
	private long id;				//ID
	private String reply; 
	private String message= "";

	

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getReply() {
		return reply;
	}

	public void setReply(String reply) {
		this.reply = reply;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	private PageList pageList;
	private UserComment userComment;
	
	public PageList getPageList() {
		return pageList;
	}

	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}

	public UserComment getUserComment() {
		return userComment;
	}

	public void setUserComment(UserComment userComment) {
		this.userComment = userComment;
	}

	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return INPUT;
		}
	}

	/**
	 * 初始页
	 */
	public String index(){
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/admin_comment.action");
		this.setPageList(this.getUserCommentService().findUserComments("id", 1, pages));
		return SUCCESS;
	}

	public String reply(){
		this.setAction("doreply");
		this.message = "";
		this.setUserComment(this.getUserCommentService().findUserCommentById(this.id));
		this.setReply(this.userComment.getReply());
		return "reply";
	}
	
	public String doreply(){
		//添加回复
		this.userComment = this.getUserCommentService().findUserCommentById(this.id);
		this.userComment.setReply(this.reply);
		this.userComment.setReplyTime(new Date());
		this.getUserCommentService().updateUserComment(userComment);
		this.message = "ok";
		return "reply";
	}


}
